<?php
class Account extends CI_Controller {

	function __construct()
	{
		parent::__construct();
	}

	function index()
	{ 
		if($this->ucenter->isauth()){
		echo '你好，世界！';
		}else{
		echo '你好，未知！';
		}
 	}
 	
	function avatar($uid,$size='small',$type='virtual')
	{
		$this->ucenter->avatar($uid,$size,$type);
	}
	
	function logout(){
		//生成同步退出的代码
		$ucsynlogout = uc_user_synlogout();
		set_cookie('authcode', '', '-86500');
		set_cookie('username', '', '-86500');
		set_cookie('uid', '', '-86500');
		exit;
	}
	
	
	function login($event=""){ 
		$G['base_url']=base_url();
	    if($event==""){
	    $this->smarty->view("account/login",$G); 
	    }
	    if($event=="check"){
	    	$inun=$this->input->post('username');
	    	$inpwd=$this->input->post('password');
	    	$remember=$this->input->post('rememberme');
			list($uid, $username, $password, $email) = uc_user_login($inun, $inpwd); 
			echo $uid;
			if($uid > 0) {
				//生成同步登录的代码
				//$ucsynlogin = uc_user_synlogin($uid);
				//用户登陆成功，设置 Cookie，加密直接用 uc_authcode 函数，用户使用自己的函数
				$this->ucenter->auth($uid, $username,$remember);
				echo 'success';  
			} elseif($uid == -1) {
				echo '用户不存在,或者被删除';
			} elseif($uid == -2) {
				echo '密码错误';
			} else {
				echo '未定义错误';
			} 
	    } 
	}
	
	
	function signup($event=""){ 
		$G['base_url']=base_url();
	    if($event==""){
	    $this->smarty->view("account/signup",$G); 
	    }
	    if($event=="reg"){
	    $username=	$this->input->post('username');
	    $password=	$this->input->post('password');
	    $email=	$this->input->post('email');
		$uid = uc_user_register($username, $password, $email);
		if($uid <= 0){
			if($uid == -1) {
				echo '用户名不合法';
			} elseif($uid == -2) {
				echo '包含要允许注册的词语';
			} elseif($uid == -3) {
				echo '用户名已经存在';
			} elseif($uid == -4) {
				echo 'Email 格式有误';
			} elseif($uid == -5) {
				echo 'Email 不允许注册';
			} elseif($uid == -6) {
				echo '该 Email 已经被注册';
			} else {
				echo '未定义';
			}
		}else{
			echo 'success'; 
		} 
	}
	
	}
}
?>